import Vue from 'vue';
import App from './views/app';
import router from './router/index';
import store from './store';
import ElementUI from 'element-ui';
import Directives from './directives';
// 表单
import CustomForm from '@/components/CustomForm';
// 页面顶部标题
import Breadcrumb from '@/components/Breadcrumb';
// 页面标题
import CustomTitle from '@/components/CustomTitle';
// 树形菜单组件
import Treeselect from '@riophae/vue-treeselect';
// 富文本组件
import Editor from "@/components/Editor"
// 详情页
import BaseDescriptions from '@/components/PageContent/BaseDescriptions';
// 基本表格
import BaseTable from '@/components/PageContent/BaseTable';
// 暂无数据
import EmptyData from '@/components/Empty'
// 基础图片卡片 
import BaseCard from '@/components/BaseCard'

import * as ECharts from 'echarts';
import { __utils } from './utils/utils';
import Pagination from '@/components/Pagination';
import 'element-ui/lib/theme-chalk/index.css';
import '@riophae/vue-treeselect/dist/vue-treeselect.css';
import './common/index.less';
import 'default-passive-events';
import '@/permission';

import { download } from '@/utils/request';
import { getDicts } from '@/api/dict/data';
import { parseTime, resetForm, resetFormData, addDateRange, selectDictLabel, selectDictLabels, handleTree } from '@/utils/ruoyi';
// 字典数据组件
import DictData from '@/components/system/DictData';
// 字典标签组件
import DictTag from '@/components/system/DictTag';
// 视频组件
// const hls = require("videojs-contrib-hls")  

// Vue.use(hls)  

Vue.config.productionTip = false;

const componentContext = require.context('@/components/BaseForm', true, /\.vue$/);
componentContext.keys().forEach(fileName => {
  //获取当前遍历的组件
  const componentConfig = componentContext(fileName);
  // console.log(componentConfig);
  //获取当前组件的文件名称
  const componentName = fileName.replace(/^\.\//, '').replace(/\.\w+$/, '');
  //注册组件
  Vue.component(componentName, componentConfig.default || componentConfig);
});

// 全局组件挂载
Vue.component('CustomForm', CustomForm);
Vue.component('Breadcrumb', Breadcrumb);
Vue.component('BaseDescriptions', BaseDescriptions);
Vue.component('BaseTable', BaseTable);
Vue.component('CustomTitle', CustomTitle);
Vue.component('Treeselect', Treeselect);
Vue.component('Pagination', Pagination);
Vue.component('DictTag', DictTag);
Vue.component('Editor', Editor)
Vue.component('EmptyData', EmptyData)
Vue.component('BaseCard', BaseCard)

Vue.use(ElementUI);
Vue.use(Directives);

Vue.prototype.$echarts = ECharts;
Vue.prototype.$utils = __utils;
Vue.prototype.$Date = Date;
Vue.prototype.getDicts = getDicts;
Vue.prototype.addDateRange = addDateRange;
Vue.prototype.selectDictLabel = selectDictLabel;
Vue.prototype.parseTime = parseTime;
Vue.prototype.resetForm = resetForm;
Vue.prototype.resetFormData = resetFormData;
Vue.prototype.download = download;

const setStyle = () => {
  var screenHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
  var _style = document.getElementById('coverStyle')
  if (!_style) {
    _style = document.createElement('style')
  }
  _style.id = "coverStyle"
  _style.type = 'text/css'
  _style.innerHTML = `
  .large_dialog .el-dialog,
  .el-dialog{
    margin-top:0!important;
  }
  `
  // 860 为最高弹窗高度
  if (screenHeight < 860) {
    document.getElementsByTagName('head')[0].appendChild(_style)
  } else {
    _style.remove()
  }
}

Vue.mixin({
  data () {
    return {
      winTableH: null,
    };
  },
  created () {
    this.$nextTick(() => {
      this.winTableH = this.$utils.resizeFullTable();
      window.onresize = () => {
        setStyle()
      }
    });
  },
});

window.onload = () => {
  setStyle()
}

DictData.install();

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app');
